package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.RolesOrderT;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

@MapperScan
public interface RolesOrderTDao {
    int deleteByPrimaryKey(Long id);

    int insert(RolesOrderT record);

    int insertSelective(RolesOrderT record);

    RolesOrderT selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(RolesOrderT record);

    int updateByPrimaryKey(RolesOrderT record);

    int updateByMap(Map map);

    @Select("select * from RolesOrder_T where Flag = 0 and Status = 1 and UserId = #{userId}")
    RolesOrderT selectNoConfirmOrder(Long userId);

    @Select("select orders.* from RolesOrder_T orders\n" +
            "  where  orders.UserId = #{userId} order by orders.CreateTime desc")
    List<RolesOrderT> selectApplyList(Long userId);

    // TODO: 2019/5/6 后期两个方法合并下
    @Select("select orders.* from RolesOrder_T orders \n" +
            "  inner join RolesOrderHandlerRelation_T relation on orders.Flag = 0 and relation.Flag = 0 and relation.OrderId = orders.ID \n" +
            "  inner join User_T users on orders.UserId = users.ID and users.Flag = 0 \n" +
            "  where orders.Status = 1 and relation.HandlerId = #{userId} order by orders.CreateTime desc")
    List<RolesOrderT> selectNoConfirmList(Long userId);

    @Select("select orders.* from RolesOrder_T orders \n" +
            "  inner join RolesOrderHandlerRelation_T relation on orders.Flag = 0 and relation.Flag = 0 and relation.OrderId = orders.ID \n" +
            "  inner join User_T users on orders.UserId = users.ID and users.Flag = 0 \n" +
            "  where orders.Status != 1 and relation.HandlerId = #{userId} order by orders.UpdateTime desc")
    List<RolesOrderT> selectConfirmedList(Long userId);

    List<Map<String,Object>> selectConfirmList(Map<String,Object> map);

    @Select("select count(*) from RolesOrder_T where Flag = 0 and Status = 4 and HandlerId = #{userId} and HandleTime >= #{currentDay}")
    int selectTodayCancelCountByUserId(@Param("userId") Long userId,@Param("currentDay") String currentDay);
}